import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
// import { join } from 'path'
import path from "path";
import Components from "unplugin-vue-components/vite";
import basicSSL from "@vitejs/plugin-basic-ssl";

// import {visualizer} from 'rollup-plugin-visualizer';


function resolve(dir) {
    return path.join(__dirname, dir);
}

export default ({mode}) => {
    const env = loadEnv(mode, process.cwd());

    return defineConfig({
        plugins: [vue(),
            // basicSSL(),
            // visualizer({
            //   open: true,
            //   gzipSize: true,
            //   brotliSize: true,
            // }),
        ],
        resolve: {
            alias: {
                "@": resolve("src"),
            },
        },
        define: {
            "process.env": {},
        },
        base: env.VITE_APP_ALD_BASE,
        build: {
            outDir: 'cloudAIWeb',
        },
        server: {
            open: true,
            host: "0.0.0.0",
            proxy: {
                '/scene_gateway': {
                    target: env.VITE_GPT_BASE_DEEP_URL,
                    changeOrigin: false,
                    // rewrite: (path) => {
                    //     return path.replace('/aiChatPageApi', '')
                    // },
                },
                // '/nl/chat/': {
                //     target: env.VITE_GPT_BASE_DEEP_URL2,
                //     changeOrigin: false,
                //     // rewrite: (path) => {
                //     //     return path.replace('/aiChatPageApi', '')
                //     // },
                // },
                '/proxy_api': {
                    target: env.VITE_GPT_BASE_DEEP_URL2,
                    changeOrigin: true,
                    rewrite: (path) => {
                        return path.replace('/proxy_api', '')
                    },
                },
                '/api': {
                    target: env.VITE_GPT_BASE_DEEP_URL3,
                    // target: "http://192.168.1.200:5000",
                    changeOrigin: false,
                },
            }
        }
    })
}
